<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
	<style type="text/css">
        #div1{
        	width:200px;height: 200px;background: red;position: absolute;top:50px;left:0;
        }
	</style>
	<script type="text/javascript">
        window.onload = function(){
        	var oBtn = document.getElementById('btn1');
        	var oDiv = document.getElementById('div1');

        	var timer = null;
        	oBtn.onclick = function(){
        		var speed = 7;
        		clearInterval(timer);//把之前的定时器全部关掉，
        		timer = setInterval(function(){    //再开启，保证只有一个定时器在工作

        			if(oDiv.offsetLeft>=300){
						clearInterval(timer);
					}else{
    				    oDiv.style.left = oDiv.offsetLeft+speed+'px';
    				};
					
				},30);
    				
        	}
        }
	</script>
</head>
<body>
   
   <input id="btn1" type="button" value="开始运动" />
   <div id="div1"></div>
	
</body>
</html>